<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>{html_table}</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="language.custom.functions.html" title="Chapter 8. Custom Functions">
<link rel="prev" href="language.function.html.select.time.html" title="{html_select_time}">
<link rel="next" href="language.function.mailto.html" title="{mailto}">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">{html_table}</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="language.function.html.select.time.html">Prev</a> </td>
<th width="60%" align="center">Chapter 8. Custom Functions</th>
<td width="20%" align="right"> <a accesskey="n" href="language.function.mailto.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="{html_table}">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="language.function.html.table"></a>{html_table}</h2></div></div></div>
<p>
   <code class="varname">{html_table}</code> is a
   <a class="link" href="language.custom.functions.html" title="Chapter 8. Custom Functions">custom function</a>
   that dumps an array of data into an HTML <code class="literal">&lt;table&gt;</code>.
   </p>
<div class="informaltable"><table border="1">
<colgroup>
<col align="center">
<col align="center">
<col align="center">
<col align="center">
<col>
</colgroup>
<thead><tr>
<th align="center">Attribute Name</th>
<th align="center">Type</th>
<th align="center">Required</th>
<th align="center">Default</th>
<th>Description</th>
</tr></thead>
<tbody>
<tr>
<td align="center">loop</td>
<td align="center">array</td>
<td align="center">Yes</td>
<td align="center"><span class="emphasis"><em>n/a</em></span></td>
<td>Array of data to loop through</td>
</tr>
<tr>
<td align="center">cols</td>
<td align="center">mixed</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>3</em></span></td>
<td>
      Number of columns in the table or a comma-separated list of column heading
      names or an array of column heading names.if the cols-attribute is empty,
      but rows are given, then the number of cols is computed by the number
      of rows and the number of elements to display to be just enough cols to
      display all elements. If both, rows and cols, are omitted cols defaults
      to 3. if given as a list or array, the number of columns is computed from
      the number of elements in the list or array.
     </td>
</tr>
<tr>
<td align="center">rows</td>
<td align="center">integer</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>empty</em></span></td>
<td>
      Number of rows in the table. if the rows-attribute is empty, but
      cols are given, then the number of rows is computed by the number of
      cols and the number of elements to display to be just enough rows to
      display all elements.
     </td>
</tr>
<tr>
<td align="center">inner</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>cols</em></span></td>
<td>
      Direction of consecutive elements in the loop-array to be
      rendered. <span class="emphasis"><em>cols</em></span> means elements are displayed
      col-by-col. <span class="emphasis"><em>rows</em></span> means elements are displayed
      row-by-row.
     </td>
</tr>
<tr>
<td align="center">caption</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>empty</em></span></td>
<td>Text to be used for the <code class="literal">&lt;caption&gt;</code>
     element of the table</td>
</tr>
<tr>
<td align="center">table_attr</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>border="1"</em></span></td>
<td>Attributes for <code class="literal">&lt;table&gt;</code> tag</td>
</tr>
<tr>
<td align="center">th_attr</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>empty</em></span></td>
<td>Attributes for <code class="literal">&lt;th&gt;</code> tag
     (arrays are cycled)</td>
</tr>
<tr>
<td align="center">tr_attr</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>empty</em></span></td>
<td>attributes for <code class="literal">&lt;tr&gt;</code> tag
     (arrays are cycled)</td>
</tr>
<tr>
<td align="center">td_attr</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>empty</em></span></td>
<td>Attributes for <code class="literal">&lt;td&gt;</code> tag
     (arrays are cycled)</td>
</tr>
<tr>
<td align="center">trailpad</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>&amp;nbsp;</em></span></td>
<td>Value to pad the trailing cells on last row with (if any)</td>
</tr>
<tr>
<td align="center">hdir</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>right</em></span></td>
<td>
      Direction of each row to be rendered. possible values:
      <span class="emphasis"><em>right</em></span> (left-to-right), and
      <span class="emphasis"><em>left</em></span> (right-to-left)
     </td>
</tr>
<tr>
<td align="center">vdir</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>down</em></span></td>
<td>
      Direction of each column to be rendered. possible values:
      <span class="emphasis"><em>down</em></span> (top-to-bottom), <span class="emphasis"><em>up</em></span>
      (bottom-to-top)
     </td>
</tr>
</tbody>
</table></div>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
   The <em class="parameter"><code>cols</code></em> attribute determines how many
   columns will be in the table.
   </p></li>
<li class="listitem"><p>
   The <em class="parameter"><code>table_attr</code></em>, <em class="parameter"><code>tr_attr</code></em>
   and <em class="parameter"><code>td_attr</code></em> values  determine the attributes given
   to the <code class="literal">&lt;table&gt;</code>, <code class="literal">&lt;tr&gt;</code>
   and <code class="literal">&lt;td&gt;</code> tags.
   </p></li>
<li class="listitem"><p>
   If <em class="parameter"><code>tr_attr</code></em> or <em class="parameter"><code>td_attr</code></em> are
   arrays, they will be cycled through.
   </p></li>
<li class="listitem"><p>
   <em class="parameter"><code>trailpad</code></em> is the value put  into the trailing cells
   on the last table row if there are any present.
   </p></li>
</ul></div>
<div class="example">
<a name="id403778"></a><p class="title"><b>Example 8.19. {html_table}</b></p>
<div class="example-contents">
<pre class="programlisting">

&lt;?php
$smarty-&gt;assign( 'data', array(1,2,3,4,5,6,7,8,9) );
$smarty-&gt;assign( 'tr', array('bgcolor="#eeeeee"','bgcolor="#dddddd"') );
$smarty-&gt;display('index.tpl');
?&gt;

  </pre>
<p>The variables assigned from php could be displayed as these three
    examples demonstrate. Each example shows the template followed by output.
    </p>
<pre class="programlisting">

{**** Example One ****}
{html_table loop=$data}

&lt;table border="1"&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;5&lt;/td&gt;&lt;td&gt;6&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;7&lt;/td&gt;&lt;td&gt;8&lt;/td&gt;&lt;td&gt;9&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;


{**** Example Two ****}
{html_table loop=$data cols=4 table_attr='border="0"'}

&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;5&lt;/td&gt;&lt;td&gt;6&lt;/td&gt;&lt;td&gt;7&lt;/td&gt;&lt;td&gt;8&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;9&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;


{**** Example Three ****}
{html_table loop=$data cols="first,second,third,fourth" tr_attr=$tr}

&lt;table border="1"&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;first&lt;/th&gt;&lt;th&gt;second&lt;/th&gt;&lt;th&gt;third&lt;/th&gt;&lt;th&gt;fourth&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr bgcolor="#eeeeee"&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;/tr&gt;
&lt;tr bgcolor="#dddddd"&gt;&lt;td&gt;5&lt;/td&gt;&lt;td&gt;6&lt;/td&gt;&lt;td&gt;7&lt;/td&gt;&lt;td&gt;8&lt;/td&gt;&lt;/tr&gt;
&lt;tr bgcolor="#eeeeee"&gt;&lt;td&gt;9&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

  </pre>
</div>
</div>
<br class="example-break">
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="language.function.html.select.time.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="language.custom.functions.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="language.function.mailto.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">{html_select_time} </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> {mailto}</td>
</tr>
</table>
</div>
</body>
</html>
